package com.ncloud.crm.mapper;

import org.apache.ibatis.annotations.*;

import com.ncloud.crm.entity.order.WorkNode;

import java.util.List;

/**
 * Created by shiqiang on 2017/4/11.
 */
@Mapper
public interface WorkNodeMapper {
    @Select(value = { "select a.*,f_get_label('NODE_TYPE',a.node_type) as node_type_name"
    		+ " ,f_get_label('NODE_SUB_TYPE',a.node_sub_type) as sub_type_name"
    		+ " ,f_get_label('ACCESS_TYPE',a.access_type) as access_type_name"
    		+ " from bs_o_node a where a.work_id = #{workId}" })
    @Results({ @Result(column = "work_id", property = "workId"), @Result(column = "modify_tag", property = "modifyTag"),
            @Result(column = "node_id", property = "nodeId"), @Result(column = "order_id", property = "orderId"),
            @Result(column="node_type",property="nodeType"),@Result(column="access_type",property="accessType"),
            @Result(column="node_type_name",property="nodeTypeName"),@Result(column="sub_type_name",property="subTypeName"),
            @Result(column="access_type_name",property="accessTypeName"),@Result(column="node_sub_type",property="nodeSubType"),
            @Result(column="eff_flag",property="effFlag"),@Result(column="node_name",property="nodeName"),
            @Result(column="begin_date",property="beginDate"),@Result(column="end_date",property="endDate"),
            @Result(column="update_time",property="updateTime"),@Result(column="update_user",property="updateUser"),
            @Result(column="cust_id",property="custId"),@Result(column="discnt_inst_id",property="discntInstId"),
            @Result(column="prod_id",property="prodId"),@Result(column="prod_inst_id",property="prodInstId"),
            @Result(column="discnt_id",property="discntId")
    })
    public List<WorkNode> getWorkNodeByWorkId(Long workId);
    @Insert(value = "insert into bs_o_node(work_id,cust_id,modify_tag,prod_inst_id,discnt_inst_id,prod_id,discnt_id,node_id,node_name,node_type,node_sub_type,access_type," +
            "eff_flag,begin_date,end_date,update_time,update_user,order_id) values(#{workId},#{custId},#{modifyTag},#{prodInstId},#{discntInstId},#{prodId},#{discntId},#{nodeId}," +
            "#{nodeName},#{nodeType},#{nodeSubType},#{accessType},#{effFlag},#{beginDate},#{endDate},#{updateTime},#{updateUser},#{orderId})")
    public int insertWorkNode(WorkNode workAttr);
    
    @Update("update bs_o_node set node_name =#{nodeName},node_type=#{nodeType},access_type=#{accessType},eff_flag=#{effFlag},"
    		+ " begin_date = #{beginDate},end_date=#{endDate},update_time=#{updateTime},update_user=#{updateUser}"
    		+ " where node_id = #{nodeId} and modify_tag=#{modifyTag}")
	public int updateWorkNode(WorkNode workNode);
    
    @Select(value = { "select a.*,f_get_label('NODE_TYPE',a.node_type) as node_type_name"
    		+ " ,f_get_label('NODE_SUB_TYPE',a.node_sub_type) as sub_type_name"
    		+ " ,f_get_label('ACCESS_TYPE',a.access_type) as access_type_name"
    		+ " from bs_o_node a where a.order_id = #{orderId}" })
    @Results({ @Result(column = "work_id", property = "workId"), @Result(column = "modify_tag", property = "modifyTag"),
            @Result(column = "node_id", property = "nodeId"), @Result(column = "order_id", property = "orderId"),
            @Result(column="node_type",property="nodeType"),@Result(column="access_type",property="accessType"),
            @Result(column="node_type_name",property="nodeTypeName"),@Result(column="sub_type_name",property="subTypeName"),
            @Result(column="access_type_name",property="accessTypeName"),@Result(column="node_sub_type",property="nodeSubType"),
            @Result(column="eff_flag",property="effFlag"),@Result(column="node_name",property="nodeName"),
            @Result(column="begin_date",property="beginDate"),@Result(column="end_date",property="endDate"),
            @Result(column="update_time",property="updateTime"),@Result(column="update_user",property="updateUser"),
            @Result(column="cust_id",property="custId"),@Result(column="discnt_inst_id",property="discntInstId"),
            @Result(column="prod_id",property="prodId"),@Result(column="prod_inst_id",property="prodInstId"),
            @Result(column="discnt_id",property="discntId")
    })
	public List<WorkNode> getNodesByOrderId(Long orderId);
}
